package com.ruoyi.business.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.business.vo.TCooperateInfoVo;
import com.ruoyi.business.service.ITCooperateInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 合作项目Controller
 *
 * @author Tellsea
 * @date 2024-07-22
 */
@Api(tags = "合作项目Controller")
@RestController
@RequestMapping("/business/cooperateInfo")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class TCooperateInfoController extends BaseController {

    private final ITCooperateInfoService tCooperateInfoService;

    @ApiOperation("查询合作项目列表")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:list')")
    @GetMapping("/list")
    public TableDataInfo<TCooperateInfoVo> list(TCooperateInfoVo entity) {
        return tCooperateInfoService.queryList(entity);
    }

    @ApiOperation("查询合作项目所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(TCooperateInfoVo entity) {
        return AjaxResult.success("查询成功", tCooperateInfoService.queryAll(entity));
    }

    @ApiOperation("导出合作项目列表")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:export')")
    @Log(title = "合作项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCooperateInfoVo entity) {
        List<TCooperateInfoVo> list = tCooperateInfoService.queryAll(entity);
        ExcelUtil<TCooperateInfoVo> util = new ExcelUtil<>(TCooperateInfoVo.class);
        util.exportExcel(response, list, "合作项目数据");
    }

    @ApiOperation("获取合作项目详细信息")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", tCooperateInfoService.queryById(id));
    }

    @ApiOperation("新增合作项目")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:add')")
    @Log(title = "合作项目", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody TCooperateInfoVo entity) {
        return toAjax(tCooperateInfoService.save(entity));
    }

    @ApiOperation("修改合作项目")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:edit')")
    @Log(title = "合作项目", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody TCooperateInfoVo entity) {
        return toAjax(tCooperateInfoService.updateById(entity));
    }

    @ApiOperation("删除合作项目")
    @PreAuthorize("@ss.hasPermi('business:cooperateInfo:remove')")
    @Log(title = "合作项目", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tCooperateInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
